﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using System.Reflection;

namespace city7.plp
{
    public static class plp_project
    {
        /*
        #region var

        public static string
                 o_l_0 = "Игорь Николаевич Коконев (4)",
                 server_1 = "localhost",
                 path_to_mdb_2 = "C:\\forAll\\Ztl20_12.mdb",
                 default_3 = "Сырье",
                 currentMode_CutPaste_4 = "4",
                 period_s_5 = "01.09.2010",
                 period_p_6 = "30.09.2010",
                 day_work_7 = "26.11.2010",
                 hasData_s_8 = "20.10.2007",
                 hasData_p_9 = "20.10.2026",
                 raz_pol_10 = "Пользователь (2)",
                 pass_11 = "999",
                 task_12 = "",
                 listAnyEdit_modeFAED_103 = "",
                 listAnyEdit_cod_104 = "",
                 listAnyEdit_name_105 = "",
                 listAnyEdit_text_106 = "",
                 listAnyEdit_1_146 = "",
                 listAnyEdit_addname_147 = "",
                 listAnyEdit_so_148 = "",
                 zakaz_current_13 = "11126006",
                 treeView_select_14 = "Суп-крем Грибной 250г (10005)",
                 zakaz_plase_current_15 = "36",
                 path_progr_files_16 = "0",
                 zakaz_kol_17 = "1",
                 zakaz_select_ct_18 = "2",
                 zakaz_td_cod123_19 = "220",
                 sir_current_doc_20 = "109231003",
                 sir_current_doc_cod123_21 = "49",
                 sir_activTypeDoc_22 = "1",
                 sir_org_23 = "Склад Сити2 (4)",
                 sir_tag_rd_24 = "0;49;20101025;Склад Сити2 (4);0;109104000",
                 editParam_date_25 = "12.10.2010",
                 sir_nd_26 = "1",
                 sir_org_sf_27 = "ИП Смолина С.И.маг У Ивана,п М.Куналей,ул Победы,д9 (2062)",
                 sir_td_cod123_28 = "0",
                 sir_td_tag_29 = "Молоко л. (2753);6;50;109251002;350",
                 sir_td_tag2_30 = "",
                 sir_path_to_skladMay_31 = "\\May\\Work\\Sklad\\Skltabl\\Skl4117.mdb",
                 size_font_in_GRID_find_32 = "22",
                 zakaz_defaultValue_33 = "74",
                 zakaz_defaultValue_price_34 = "80",
                 tree_position_Width_35 = "710",
                 tree_position_Height_36 = "715",
                 tree_position_Width_TOV_37 = "710",
                 tree_MODE_WAED_38 = "3",
                 show_fpa_0InWork_1fiskal_888all_39 = "0",
                 fiskalDocAfterPrint_0no_1yes_40 = "1";
        #endregion
        */
        public static int i(object so) { return Convert.ToInt32(so); }
        public static double d(object so) { return Convert.ToDouble(so); }


        public static string
                currentMode_0 = "0",
                currentMode_folder_object = "0",
                s11 = "1", s12 = "2", s13 = "3", s14 = "4", s15 = "5", s16 = "6", s17 = "7";


    }
    
    public class loadSave_Static_ToDataTable
    {

        //public void loadSave_Static_ToDataTableT<T>()
        //{
        //    Type tt = typeof(T);//et.GetType();
        //    string[] gn = Enum.GetNames(tt);//(EmpType)Enum.Parse(typeof(EmpType), "Manager");

        //    foreach (string s in gn)
        //    {
        //        //functionService.shorts.m(Enum.Parse(tt, s));
        //        functionService.shorts.m(ConvertTo<T>(s));
        //        // functionService.shorts.m(GetValue_Name_Description(ConvertTo<T>(s)));
        //    }
        //}

        public DataTable lookXML(string fileNameWithoutExt)
        {
            string sp = string.Concat("PLP\\", fileNameWithoutExt, ".xml");
            DataTable dt = new DataTable();
            dt.ReadXml(sp); return dt;
        }
        public DataTable lookVar()
        {

            DataTable dt = new DataTable("dt");
            dt.Columns.Add("cod", typeof(int)); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("prim", typeof(string));

            dt.AcceptChanges();

            DataRow r;
            FieldInfo[] mi;
            Type mt = typeof(plp_project);
            mi = mt.GetFields();
            int i = 0;
            foreach (FieldInfo fi in mi)
            {
                i++;
                r = dt.NewRow();
                r[0] = i; r[1] = fi.GetValue(mt); r[2] = fi.Name;
                dt.Rows.Add(r);
            }
            dt.AcceptChanges(); return dt;
        }
        public void save(string fileNameWithoutExt)
        {

            string sp = string.Concat("PLP\\", fileNameWithoutExt, ".xml");

            DataTable dt = new DataTable("dt");
            dt.Columns.Add("cod", typeof(int));
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("prim", typeof(string));

            dt.AcceptChanges();

            DataRow r;
            FieldInfo[] mi;
            Type mt = typeof(plp_project);
            mi = mt.GetFields();
            int i = 0;
            foreach (FieldInfo fi in mi)
            {
                i++;
                r = dt.NewRow();
                r[0] = i; r[1] = fi.GetValue(mt); r[2] = fi.Name;
                dt.Rows.Add(r);
            }
            dt.AcceptChanges(); dt.WriteXml(sp, XmlWriteMode.WriteSchema);// rp.sh(dt);
        }
        public void load(string fileNameWithoutExt)
        {
            string sp = string.Concat("PLP\\", fileNameWithoutExt, ".xml");
            DataTable dt = new DataTable();
            dt.ReadXml(sp);

            FieldInfo[] mi;
            Type mt = typeof(plp_project);
            mi = mt.GetFields();
            int i = 0;
            foreach (FieldInfo fi in mi)
            {
                fi.SetValue(mt, dt.Rows[i][1].ToString()); i++;
            }
        }
    }
}
